

let fs = require("fs")

let jf = require("json-format")

let path = "F:/B09 v1.4.3606/Data/Core/Defs/ThingDefs_Items/Items_Resource_Stuff_Leather.xml"



let str = fs.readFileSync(path).toString();




let matchs = str.match(/<ThingDef(?:(?!<\/ThingDef>)[\w\W])+<\/ThingDef>/ig)


let arr = matchs.map(v => {
    let data = {}
    let sts = ["label","MarketValue","StuffPower_Armor_Sharp","StuffPower_Armor_Blunt", "StuffPower_Armor_Heat","StuffPower_Insulation_Cold","StuffPower_Insulation_Heat","commonality","MaxHitPoints","Beauty"];
    sts.forEach(s => {
        let reg = new RegExp(`<${s}>([^<]+)<`)
        if(reg.test(v)) {
            data[s] = RegExp.$1;
        }
    })
    return data
});




arr.sort(function (a, b) {
    return ((a.StuffPower_Insulation_Heat-0)||16) - ((b.StuffPower_Insulation_Heat-0)||16);
});

fs.writeFileSync("./leather.js", jf(arr))